/**
 *
 */
package com.wedroid.r2d2.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.core.persistence.GenericJdbcSupport;
import com.wedroid.entity.contact.Droid;

/**
 * @author lute
 */
@Repository
public class DroidDaoSupport {

    @Autowired
    private GenericJdbcSupport genericJdbcSupport;

    /**
     * @param name
     * @return
     */
    public Droid getDroidByName(String name) {
        String sentence = "SELECT id AS id, name AS name, nick_name AS 'profile.nick_name', remark_name AS 'profile.remark_name', display_name AS 'profile.display_name', head_img_url AS 'profile.head_img_url', contact_flag AS 'profile.contact_flag', member_count AS 'profile.member_count', alias AS 'profile.alias', sex AS 'profile.sex', province AS 'profile.province', city AS 'profile.city', signature AS 'profile.signature' FROM droid WHERE name = :name";
        return genericJdbcSupport.queryForObject(sentence, "name", name, Droid.class);
    }

    /**
     * @param droid
     */
    public void createDroid(Droid droid) {
        String sentence = "INSERT INTO droid (name, nick_name, remark_name, display_name, head_img_url, contact_flag, member_count, alias, sex, province, city, signature) VALUES (:name, :profile.nickName, :profile.remarkName, :profile.displayName, :profile.headImgUrl, :profile.contactFlag, :profile.memberCount, :profile.alias, :profile.sex, :profile.province, :profile.city, :profile.signature)";
        genericJdbcSupport.save(sentence, droid);
    }

    /**
     * @param droid
     */
    public void updateDroidProfile(Droid droid) {
        String sentence = "UPDATE droid set remark_name = :profile.remarkName, display_name = :profile.displayName, head_img_url = :profile.headImgUrl, contact_flag = :profile.contactFlag, member_count = :profile.memberCount, alias = :profile.alias, sex = :profile.sex, province = :profile.province, city = :profile.city, signature = :profile.signature";
        genericJdbcSupport.executeSQL(sentence, droid);
    }

}
